package wallet

import (
	"context"
	"go.uber.org/zap"
	"navi-mumbai/common/ctxdata"
	"navi-mumbai/common/xerr"

	"navi-mumbai/app/api/business/internal/svc"
	"navi-mumbai/app/api/business/internal/types"
	"navi-mumbai/app/rpc/wallet/pb"

	"github.com/jinzhu/copier"
	"github.com/zeromicro/go-zero/core/logx"
)

type GetUserDepositFlowListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetUserDepositFlowListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserDepositFlowListLogic {
	return &GetUserDepositFlowListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetUserDepositFlowListLogic) GetUserDepositFlowList(req *types.UserDepositFlowListReq) (resp *types.UserDepositFlowListResp, err error) {
	uid := ctxdata.GetUidFromCtx(l.ctx)
	if uid != req.Uid {
		return nil, xerr.NewGrpcErrCodeMsg(xerr.AuthFail, "no privilege")
	}
	var in pb.UserDepositFlowListReq
	_ = copier.Copy(&in, req)
	var rsp *pb.UserDepositFlowListResp
	rsp, err = l.svcCtx.WalletUsersRpc.UserDepositFlowList(l.ctx, &in)
	if err != nil {
		l.Logger.Errorf("err == ", zap.Error(err))
		return nil, err
	}
	resp = &types.UserDepositFlowListResp{
		List: make([]*types.DepositFlow, 0),
	}
	_ = copier.Copy(resp, rsp)
	return
}
